<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>教育考试系统 - 登录</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">

  <!-- 配置Tailwind自定义主题，与主页面保持一致 -->
  <script>
    tailwind.config = {
      theme: {
        extend: {
          colors: {
            primary: '#165DFF',
            secondary: '#36D399',
            accent: '#FF9F43',
            neutral: '#F8FAFC',
            'neutral-dark': '#334155',
          },
          fontFamily: {
            inter: ['Inter', 'system-ui', 'sans-serif'],
          },
        },
      }
    }
  </script>

  <style type="text/tailwindcss">
    @layer utilities {
      .content-auto {
        content-visibility: auto;
      }
      .card-shadow {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
      }
      .btn-primary {
        @apply bg-primary text-white px-4 py-2 rounded-lg transition-all duration-300 hover:bg-primary/90 active:bg-primary/80;
      }
      .btn-secondary {
        @apply bg-white border border-gray-200 text-neutral-dark px-4 py-2 rounded-lg transition-all duration-300 hover:bg-gray-50 active:bg-gray-100;
      }
      .input-field {
        @apply w-full px-4 py-2.5 rounded-lg border border-gray-200 focus:border-primary focus:ring-1 focus:ring-primary transition-all outline-none;
      }
    }
  </style>
</head>
<body class="font-inter bg-gray-50 text-neutral-dark min-h-screen flex items-center justify-center p-4">
  <div class="w-full max-w-5xl grid grid-cols-1 lg:grid-cols-2 gap-8">
    <!-- 左侧品牌展示区 -->
    <div class="hidden lg:flex flex-col justify-center bg-primary rounded-2xl p-8 text-white">
      <div class="flex items-center space-x-2 mb-8">
        <i class="fa fa-graduation-cap text-3xl"></i>
        <h1 class="text-2xl font-bold">智慧教育考试系统</h1>
      </div>

      <h2 class="text-[clamp(1.5rem,3vw,2.5rem)] font-bold mb-4">高效、智能的<br>教育考试解决方案</h2>

      <p class="text-white/80 mb-8">
        为教师提供便捷的考试管理和数据分析工具，为学生创造高效的学习和测评环境
      </p>

      <div class="space-y-6 mt-8">
        <div class="flex items-start space-x-4">
          <div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center flex-shrink-0 mt-1">
            <i class="fa fa-tachometer"></i>
          </div>
          <div>
            <h3 class="font-medium text-lg">智能数据分析</h3>
            <p class="text-white/70 text-sm mt-1">全面追踪学习进度和考试表现</p>
          </div>
        </div>

        <div class="flex items-start space-x-4">
          <div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center flex-shrink-0 mt-1">
            <i class="fa fa-shield"></i>
          </div>
          <div>
            <h3 class="font-medium text-lg">安全可靠</h3>
            <p class="text-white/70 text-sm mt-1">保障考试公平和数据安全</p>
          </div>
        </div>

        <div class="flex items-start space-x-4">
          <div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center flex-shrink-0 mt-1">
            <i class="fa fa-mobile"></i>
          </div>
          <div>
            <h3 class="font-medium text-lg">多端适配</h3>
            <p class="text-white/70 text-sm mt-1">随时随地进行学习和考试</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 右侧登录表单区 -->
    <div class="bg-white rounded-2xl p-6 md:p-8 card-shadow">
      <div class="lg:hidden flex items-center space-x-2 mb-6">
        <i class="fa fa-graduation-cap text-primary text-2xl"></i>
        <h1 class="text-xl font-bold text-primary">智慧教育考试系统</h1>
      </div>

      <h2 class="text-[clamp(1.5rem,3vw,2rem)] font-bold mb-6">欢迎登录</h2>

      <!-- 身份选择 -->
      <div class="mb-8">
        <h3 class="text-sm font-medium text-gray-500 mb-2">选择身份</h3>
        <div class="flex rounded-lg overflow-hidden border border-gray-200">
          <button id="teacher-login-tab" class="flex-1 py-3 px-4 bg-primary text-white text-sm font-medium transition-all">
            教师登录
          </button>
          <button id="student-login-tab" class="flex-1 py-3 px-4 bg-white text-gray-600 text-sm font-medium hover:bg-gray-50 transition-all">
            学生登录
          </button>
        </div>
      </div>

      <!-- 登录表单 -->
      <form>
        <div class="mb-4">
          <label for="username" class="block text-sm font-medium text-gray-700 mb-1">用户名</label>
          <div class="relative">
            <span class="absolute inset-y-0 left-0 flex items-center pl-4 text-gray-500">
              <i class="fa fa-user"></i>
            </span>
            <input type="text" id="username" class="input-field pl-10" placeholder="请输入用户名" required>
          </div>
        </div>

        <div class="mb-6">
          <div class="flex justify-between items-center mb-1">
            <label for="password" class="block text-sm font-medium text-gray-700">密码</label>
<!--            <a href="#" class="text-sm text-primary hover:underline">忘记密码?</a>-->
          </div>
          <div class="relative">
            <span class="absolute inset-y-0 left-0 flex items-center pl-4 text-gray-500">
              <i class="fa fa-lock"></i>
            </span>
            <input type="password" id="password" class="input-field pl-10" placeholder="请输入密码" required>
            <button type="button" class="absolute inset-y-0 right-0 flex items-center pr-4 text-gray-500 hover:text-primary">
              <i class="fa fa-eye-slash"></i>
            </button>
          </div>
        </div>

<!--        <div class="mb-6">-->
<!--          <label class="flex items-center">-->
<!--            <input type="checkbox" class="w-4 h-4 accent-primary">-->
<!--            <span class="ml-2 text-sm text-gray-600">记住我 30 天</span>-->
<!--          </label>-->
<!--        </div>-->

        <button type="button" class="btn-primary w-full py-3 text-base font-medium mb-4" id="login">
          登录系统
        </button>
         <div class="text-center text-sm text-gray-500">
          <span>还没有账号? </span>
          <a href="/register" class="text-primary hover:underline">点击注册</a>
        </div>
      </form>
    </div>
  </div>

  <footer class="fixed bottom-4 left-0 right-0 text-center text-gray-500 text-sm">
    <p>© 2025 智慧教育考试系统 版权所有</p>
  </footer>

  <script>
    //创建全局变量
    let Identity = '教师'
    // 身份切换功能
    const setupLoginRoleSwitch = () => {
      const teacherTab = document.getElementById('teacher-login-tab');
      const studentTab = document.getElementById('student-login-tab');

      teacherTab.addEventListener('click', () => {
        Identity = '教师'
        // 更新标签样式
        teacherTab.classList.add('bg-primary', 'text-white');
        teacherTab.classList.remove('bg-white', 'text-gray-600', 'hover:bg-gray-50');
        studentTab.classList.add('bg-white', 'text-gray-600', 'hover:bg-gray-50');
        studentTab.classList.remove('bg-primary', 'text-white');
      });

      studentTab.addEventListener('click', () => {
        Identity = '学生'
        // 更新标签样式
        studentTab.classList.add('bg-primary', 'text-white');
        studentTab.classList.remove('bg-white', 'text-gray-600', 'hover:bg-gray-50');
        teacherTab.classList.add('bg-white', 'text-gray-600', 'hover:bg-gray-50');
        teacherTab.classList.remove('bg-primary', 'text-white');
      });
    };

    // 密码显示/隐藏功能
    const setupPasswordToggle = () => {
      const toggleBtn = document.querySelector('.fa-eye-slash').parentElement;
      const passwordInput = document.getElementById('password');

      toggleBtn.addEventListener('click', () => {
        const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
        passwordInput.setAttribute('type', type);

        // 切换图标
        const icon = toggleBtn.querySelector('i');
        if (type === 'password') {
          icon.classList.remove('fa-eye');
          icon.classList.add('fa-eye-slash');
        } else {
          icon.classList.remove('fa-eye-slash');
          icon.classList.add('fa-eye');
        }
      });
    };

    //登录按钮
    login_button = document.getElementById('login')
    login_button.addEventListener('click',async () => {

      username = document.getElementById('username').value
      password = document.getElementById('password').value

      formdata = new FormData()
      formdata.append('username', username)
      formdata.append('password', password)
      formdata.append('Identity', Identity)

      const response = await fetch('/',{
        method: 'POST',
        body: formdata
      })

      result = await response.json()

      if(result.success){
        alert('登录成功')
        window.location.href = result.redirect || '/'
      }
      else {
        alert(result.error)
      }
    })

    // 页面加载完成后初始化
    document.addEventListener('DOMContentLoaded', () => {
      setupLoginRoleSwitch();
      setupPasswordToggle();
    });
  </script>
</body>
</html>